# ---------- 编译 ----------
FROM docker.m.daocloud.io/alpine:3.18 AS builder

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add --no-cache g++ musl-dev git linux-headers asio-dev wget

WORKDIR /src
COPY src/main.cpp ./

# 获取 Crow 单头文件
RUN https://github.com/CrowCpp/Crow/releases/download/v1.2.1.2/crow_all.h

# 静态链接（musl 自带完整的 libc.a）
RUN g++ -std=c++17 -O2 -static main.cpp -o tiny-json-rest -pthread -I.

# ---------- 运行 ----------
FROM scratch
COPY --from=builder /src/tiny-json-rest /tiny-json-rest
# 空数据库 & 鉴权文件
COPY db.json   /db.json
COPY .env      /.env

EXPOSE 8080
ENTRYPOINT ["/tiny-json-rest"]